// ip正则表达式
export const isValidIP = (str) => {
    const strs = String(str);
    // 原来代码const reg =
    // 原来代码/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
    const reg =
      /^(?:(?<firstOctet>\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.)(?<secondOctet>\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(?<thirdOctet>\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(?<fourthOctet>\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
  
    return reg.test(strs);
  };
  
  export const isValidIPRange = (str) => {
    const strs = String(str);
    const reg =
      /^(?:(?<firstOctet255>(?<twentyFiveRange255>25[0-5]))\.){0,1}(?:(?<firstOctet240to254>(?<range240to254>2[0-4][0-9]))\.){0,1}(?:(?<firstOctet192to239>(?:[01]?[0-9][0-9]?))\.){0,1}(?:(?<secondOctet255>(?<twentyFiveRange255_2>25[0-5]))\.){0,1}(?:(?<secondOctet240to254>(?<range240to254_2>2[0-4][0-9]))\.){0,1}(?:(?<secondOctet192to239>(?:[01]?[0-9][0-9]?))\.){0,1}(?:(?<thirdOctet255>(?<twentyFiveRange255_3>25[0-5]))\.){0,1}(?:(?<thirdOctet240to254>(?<range240to254_3>2[0-4][0-9]))\.){0,1}(?:(?<thirdOctet192to239>(?:[01]?[0-9][0-9]?))\.){0,1}(?<fourthOctet255>(?<twentyFiveRange255_4>25[0-5]))\.(?<fourthOctet240to254>(?<range240to254_4>2[0-4][0-9]))\.(?<fourthOctet192to239>(?:[01]?[0-9][0-9]?))\/(?:(?:[1-2]?[0-9]|3[0-2]))$/;
    const flag = reg.test(strs);
    return flag;
  };
  
  export const isValidIpv4OrIpv6 = (str, callback) => {
    const strs = String(str);
    // IPv4正则表达式
    const ipv4Regex =
      /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    // IPv6正则表达式
    const ipv6Regex =
      /^(?<a>[\da-fA-F]{1,4}:){6}(?<b>(?<aaa>25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$|^::(?<c>[\da-fA-F]{1,4}:){0,4}(?<d>(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$|^(?<e>[\da-fA-F]{1,4}:):(?<f>[\da-fA-F]{1,4}:){0,3}(?<g>(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$|^(?<h>[\da-fA-F]{1,4}:){2}:(?<l>[\da-fA-F]{1,4}:){0,2}(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$|^(?<m>[\da-fA-F]{1,4}:){3}:(?:[\da-fA-F]{1,4}:){0,1}(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$|^(?<n>[\da-fA-F]{1,4}:){4}:(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$|^(?<o>[\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$|^:(?<p>(?<aaaaap>:[\da-fA-F]{1,4}){1,6}|:)$|^[\da-fA-F]{1,4}:(?:(?<aaaab>:[\da-fA-F]{1,4}){1,5}|:)$|^(?<q>[\da-fA-F]{1,4}:){2}(?<r>(?<aaaar>:[\da-fA-F]{1,4}){1,4}|:)$|^(?:[\da-fA-F]{1,4}:){3}(?<aa>(?<aaaaac>:[\da-fA-F]{1,4}){1,3}|:)$|^(?<ab>[\da-fA-F]{1,4}:){4}(?<ac>(?<aaaaad>:[\da-fA-F]{1,4}){1,2}|:)$|^(?<ad>[\da-fA-F]{1,4}:){5}:(?<ae>[\da-fA-F]{1,4})?$|^(?<af>[\da-fA-F]{1,4}:){6}:$/;
    const flag1 = ipv4Regex.test(strs);
    const flag2 = ipv6Regex.test(strs);
    return flag1 || flag2;
  };
  
  export const isValidDomain = (domain) => {
    // 原来代码const regex = /^(?!:\/\/)([a-zA-Z0-9-_]+\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\.[a-zA-Z]{2,}(:\d{1,5})?\/?$/;
    const regex =
      /^(?!:\/\/)(?<all>(?<subdomains>(?<part>[a-zA-Z0-9-_]+\.)*)(?<domain>[a-zA-Z0-9][a-zA-Z0-9-_]+)\.(?<tld>[a-zA-Z]{2,})(?<port>:?(?:\d{1,5}))?)/;
    return regex.test(domain);
  };
  
  // 域名加IP
  export const isValidDomain_ = (rule, str, callback) => {
    const regex =
      /^(?!:\/\/)(?<all>(?<subdomains>(?<part>[a-zA-Z0-9-_]+\.)*)(?<domain>[a-zA-Z0-9][a-zA-Z0-9-_]+)\.(?<tld>[a-zA-Z]{2,})(?<port>:?(?:\d{1,5}))?)/;
    const ipv4Regex =
      /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    // IPv6正则表达式
    const ipv6Regex =
      /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|(?:[0-9a-fA-F]{1,4}:){0,1}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])$/;
  
    const flag1 = ipv4Regex.test(str);
    const flag2 = ipv6Regex.test(str);
    const flag = regex.test(str);
    if (flag || flag1 || flag2) {
      callback();
    } else {
      callback(new Error('服务器地址输入有问题'));
    }
  };
  
  // 汉字和数字表达式
  export const isValidChineseNum = (str) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa50-9]+$/;
    return reg.test(strs);
  };
  
  // 纯数字表达式
  export const isValidNum = (str) => {
    const strs = String(str);
    const reg = /^[0-9]+$/;
    return reg.test(strs);
  };
  
  // 汉字和数字和字母
  export const isValidChineseNumAlph = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa50-9a-zA-Z]+$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('只能输入汉字、数字和字母'));
    }
  };
  
  // 汉字和数字和字母和_表达式
  export const isValidChineseNumAlph_ = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa50-9a-zA-Z_]+$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('格式有问题'));
    }
  };
  export const isValidChineseNumAlphBool = (str) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa50-9a-zA-Z_]+$/;
    return reg.test(strs);
  };
  // 汉字和字母表达式
  export const isValidChineseEn = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa5a-zA-Z]+$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('只允许中英文，大小写，不允许出现特殊字符和数字'));
    }
  };
  export const isValidChineseEnBool = (str) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa5a-zA-Z]+$/;
    return reg.test(strs);
  };
  // 汉字和数字和字母和_-表达式
  export const isValidChineseNumAlphZ = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa50-9a-zA-Z_-]+$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('仅支持数字、中英文字母和-_字符'));
    }
  };
  
  export const isValidChineseNumAlphZBool = (str) => {
    const strs = String(str);
    const reg = /^[\u4e00-\u9fa50-9a-zA-Z_-]+$/;
    return reg.test(strs);
  };
  // 数字或者字母
  export const isValidAlphNum = (str) => {
    const strs = String(str);
    const reg = /^[0-9A-Za-z]+$/;
    return reg.test(strs);
  };
  
  // 英文字母开头，可以有下划线
  export const isValidLetter = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[a-z][a-z\_]*$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('只能输入小写字母和下划线，且必须以英文字母开头'));
    }
  };
  // 字母、数字和_-，且必须以英文字母开头
  export const isValidLetterNum = (rule, str, callback) => {
    // 将传入的字符串转换为字符串类型
    const strs = String(str);
    const reg = /^[a-zA-Z][a-zA-Z0-9\-_]*$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('只能输入字母、数字和_-，且必须以英文字母开头'));
    }
  };
  // 英文字母开头，可以有下划线，数字
  export const isValidNetworkID = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[a-zA-Z][a-zA-Z0-9\_]*$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('只能输入字母、数字和下划线，且必须以英文字母开头'));
    }
  };
  
  // 字母，下划线
  export const isValidParameter = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[a-zA-Z][a-zA-Z\_]*$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('只能输入字母和下划线，且必须以英文字母开头'));
    }
  };
  
  // 字母、数字和小数点
  export const isValidVersion = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[a-zA-Z0-9][a-zA-Z0-9\.]*$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('字母或数字开头，可包含字母、数字和小数点'));
    }
  };
  // 数字和小数点
  export const isValidVersionNum = (rule, str, callback) => {
    const strs = String(str);
    const reg =
      /^(?<majorPart>\d+)(?:\.(?<minorPart>\d+))*(?:\.(?<patchPart>\d+))*$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(
        new Error(
          '版本号必须数字开头和结尾，只能包含数字和小数点，且小数点不可连续',
        ),
      );
    }
  };
  // 账号（字母开头，可包含字母、数字）
  export const isValidCode = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[a-zA-Z][a-zA-Z0-9]*$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('字母开头，可包含字母、数字'));
    }
  };
  
  // 汉字正则表达式
  export const isValidChinese = (rule, str, callback) => {
    const strs = String(str);
    const reg = /[\u4e00-\u9fa5]/gm;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('只允许输入汉字'));
    }
  };
  
  // 手机号码
  export const isValidPhone = (rule, str, callback) => {
    const strs = String(str);
    const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    const flag = reg.test(strs);
    if (flag) {
      callback();
    } else {
      callback(new Error('手机号码格式有问题'));
    }
  };
  
  export const isBoolValidPhone = (str) => {
    const strs = String(str);
    const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    return reg.test(strs);
  };
  
  export const endDomainList = [
    '.com',
    '.cn',
    '.edu',
    '.gov',
    '.int',
    '.net',
    '.org',
    '.biz',
    '.pro',
    '.info',
    '.coop',
    '.aero',
  ];
  
  // 邮箱
  export const isValidEmail = (rule, str, callback) => {
    const strs = String(str);
    const reg =
      /^[A-Za-z0-9]+(?<local_part>[._\\-]*[A-Za-z0-9])*@(?<domain>[A-Za-z0-9]+[-A-Za-z0-9]*[A-Za-z0-9]+.){1,63}[A-Za-z0-9]+$/;
    const flag = reg.test(strs);
    if (flag) {
      let domain = strs.split('@')[1];
      let isEnd = false;
      endDomainList.forEach((element) => {
        if (domain.endsWith(element)) {
          isEnd = true;
        }
      });
  
      if (isEnd) {
        callback();
      } else {
        let msg =
          '您输入的邮箱后缀不在名单中，目前支持.com,.cn,.edu,.gov,.int,.net,.org,.biz,.pro,.info,.coop,.aero';
        callback(new Error(msg));
      }
    } else {
      callback(new Error('邮箱格式有误，请重新输入'));
    }
  };
  // 主要判断是否提示过长文本，如果过长需要增加间距
  export const isValidEmailBool = (str) => {
    const strs = String(str);
    const reg =
      /^[A-Za-z0-9]+(?<local_part>[._\\-]*[A-Za-z0-9])*@(?<domain>[A-Za-z0-9]+[-A-Za-z0-9]*[A-Za-z0-9]+.){1,63}[A-Za-z0-9]+$/;
    const flag = reg.test(strs);
    if (flag) {
      let domain = strs.split('@')[1];
      let isEnd = false;
      endDomainList.forEach((element) => {
        if (domain.endsWith(element)) {
          isEnd = true;
        }
      });
  
      return isEnd;
    } else {
      return true;
    }
  };
  export const isNotRequiredValidEmail = (rule, str, callback) => {
    const strs = String(str);
    if (!strs) {
      callback();
    }
    const reg =
      /^[A-Za-z0-9]+(?<local_part>[._\\-]*[A-Za-z0-9])*@(?<domain>[A-Za-z0-9]+[-A-Za-z0-9]*[A-Za-z0-9]+.){1,63}[A-Za-z0-9]+$/;
    const flag = reg.test(strs);
  
    if (flag) {
      let isEnd = false;
      let domain = strs.split('@')[1];
      endDomainList.forEach((element) => {
        if (domain.endsWith(element)) {
          isEnd = true;
        }
      });
      if (isEnd) {
        callback();
      } else {
        callback(
          new Error(
            '您输入的邮箱后缀不在名单中，目前支持.com,.cn,.edu,.gov,.int,.net,.org,.biz,.pro,.info,.coop,.aero',
          ),
        );
      }
    } else {
      callback(new Error('邮箱格式有误，请重新输入'));
    }
  };
  
  export const isBoolValidEmail = (str) => {
    const strs = String(str);
    const reg =
      /^[A-Za-z0-9]+(?<local_part>[._\\-]*[A-Za-z0-9])*@(?<domain>[A-Za-z0-9]+[-A-Za-z0-9]*[A-Za-z0-9]+.){1,63}[A-Za-z0-9]+$/;
    const flag = reg.test(strs);
    let isEnd = false;
    if (flag) {
      let domain = strs.split('@')[1];
      endDomainList.forEach((element) => {
        if (domain.endsWith(element)) {
          isEnd = true;
        }
      });
    }
    return flag && isEnd;
  };
  // 是否为正整数
  export const isPositiveInteger = (s) => {
    const re = /^[0-9]+$/;
    return re.test(s);
  };
  
  export const isPort = (str) => {
    const parten = /^(?<digits>\d)+$/g;
    if (parten.test(str) && parseInt(str) <= 65535 && parseInt(str) >= 0) {
      return true;
    } else {
      return false;
    }
  };
  
  // 特殊符号检测
  export const isReg = (str) => {
    const pattern = new RegExp(
      "[`~!@#$^&*()=|{}':;'\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘”“'？ ]",
    );
    if (pattern.test(str)) {
      return true;
    }
    return false;
  };
  
  // 密码检测
  export const validatePassword = (rule, password, callback) => {
    const regex =
      /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+';,./-=<>?:"]).{8,16}$/;
    const flag = regex.test(password);
    if (flag) {
      callback();
    } else {
      callback(
        new Error(
          '密码需8-16个字符，含大写字母、小写字母和数字，可加特殊字符，空格除外',
        ),
      );
    }
  };
  
  // 查表得知：
  // 数字0~9对应的ASCII码值是 48-57
  // 大写字母A-Z对应的ASCII码值是 65-90
  // 小写字母a-z对应的ASCII码值是 97-122
  // 特殊字符对应的ASCII码的值是33-47 58-64
  export const getPassword = (length) => {
    // 定义一个空数组保存我们的密码
    let passArrItem = [];
    // 定义获取密码成员的方法
    const getNumber = () => crypto.getRandomValues(new Uint32Array(1)) % 10; // 0~9的数字
    const getUpLetter = () =>
      String.fromCharCode((crypto.getRandomValues(new Uint32Array(1)) % 26) + 65); // A-Z
    const getLowLetter = () =>
      String.fromCharCode((crypto.getRandomValues(new Uint32Array(1)) % 26) + 97); // a-z
    const getCode = () =>
      String.fromCharCode(
        (crypto.getRandomValues(new Uint32Array(1)) % 15) + 33,
      ) ||
      String.fromCharCode((crypto.getRandomValues(new Uint32Array(1)) % 7) + 58);
  
    // 将获取成员的方法保存在一个数组中方便用后面生成的随机index取用
    const passMethodArr = [getNumber, getUpLetter, getLowLetter, getCode];
  
    // 随机index
    const getIndex = () => crypto.getRandomValues(new Uint32Array(1)) % 4;
  
    // 从0-9，a-z，A-Z，以及特殊字符中随机获取一项
    const getPassItem = () => passMethodArr[getIndex()]();
  
    // 不多解释
    Array(length - 4)
      .fill('')
      .forEach(() => {
        passArrItem.push(getPassItem());
      });
  
    const confirmItem = [getNumber(), getUpLetter(), getLowLetter(), getCode()];
  
    // 加上我们确认的四项，从而使生成的密码，大写字母、小写字母、数字和特殊字符至少各包含一个
    passArrItem.push(...confirmItem);
  
    // 转为字符串返回
    return passArrItem.join('');
  };
  
  // 输出我们获取到的包含大写、小写字母和数字的8位字符串密码
  
  /**
   * 验证经度输入范围在-180-180之间，且小数可7位
   * @param {*} rule
   * @param {*} value
   * @param {*} callback
   */
  
  /**
   * 验证纬度输入范围在-180-180之间，且小数可7位
   * @param {*} rule
   * @param {*} value
   * @param {*} callback
   */
  export const checkLat = (rule, value1, callback) => {
    let value = value1;
    if (value) {
      value = String(value);
      // 原来/^(?<sign>\-|\+)?(?<latitudeValue>([0-8]?\d{1}\.\d{0,7}|90\.0{0,6}|[0-8]?\d{1}|90))$/
      if (
        value.match(
          /^(?<sign>[\-+]?)?(?<latitudeValue>(?<latitudePart>[0-8]?\d{1}\.\d{0,7}|90\.0{0,6}|[0-8]?\d{1}|90))$/,
        )
      ) {
        callback();
      } else {
        callback(new Error('纬度为-90~90,小数限7位'));
      }
    } else {
      callback();
    }
  };
  
  export const isCheckLon = (value1) => {
    return (
      value1 != null &&
      /^(?<sign>[\-+]?)?(?<number>(?<decimalNumber>(?<part1>\d|[1-9]\d|1[0-7]\d|0{1,3})\.\d{0,7})|(?<part2>\d|[1-9]\d|1[0-7]\d|0{1,3})|180\.0{0,6}|180)$/.test(
        String(value1),
      )
    );
  };
  
  /**
   * 验证纬度输入范围在-180-180之间，且小数可7位
   * @param {*} rule
   * @param {*} value
   * @param {*} callback
   */
  export const isCheckLat = (value1) => {
    return (
      value1 &&
      /^(?:[\-+]?)?(?:[0-8]?\d{1}\.\d{0,7}|90\.0{0,6}|[0-8]?\d{1}|90)$/.test(
        String(value1),
      )
    );
  };
  
  // 用户名称中文名称校验
  export const validateUserName = (rule, value, callback) => {
    const regexpName = /^[^\s！@#￥%……&*（）]{2,10}$/;
    const flag = regexpName.test(value);
    if (flag) {
      callback();
    } else {
      callback(new Error('2-10个字符，且不能输入以下字符 ！@#￥%……&*（）'));
    }
  };
  
  // 32中文名称校验
  export const validateName = (rule, value, callback) => {
    const regexpName = /^[^！!@#￥%$^&*"、（）()<>……\s]{1,32}$/;
    const flag = regexpName.test(value);
    if (flag) {
      callback();
    } else {
      callback(
        new Error('限制32个字符，且不能输入空格和以下字符！@#￥%$^&*"、（）<>……'),
      );
    }
  };
  
  // 32英文名称校验
  export const validateNameEn = (rule, value, callback) => {
    const regexp = /^[^！@#￥%……&*（）<>"!@#$%^&*()、\s\u4e00-\u9fa5]{1,32}$/;
    const flag = regexp.test(value);
    if (flag) {
      callback();
    } else {
      callback(
        new Error(
          '限制32个字符，且不能输入中文、空格和以下字符！@#￥%$^&*"、（）<>……',
        ),
      );
    }
  };
  // 16字中文，不含英文数字和特殊字符
  export const validateChineseName16 = (rule, value, callback) => {
    const regexpName = /^[\u4e00-\u9fa5]{1,16}$/;
    const flag = regexpName.test(value);
    if (flag) {
      callback();
    } else {
      callback(
        new Error(
          '限制16个字符，且不能输入英文、空格和以下字符！@#￥%$^&*"、（）<>……',
        ),
      );
    }
  };
  // 16中文名称校验
  export const validateName16 = (rule, value, callback) => {
    const regexpName = /^[^！@#￥%……&*（）<>"!@#$%^&*()、\s]{1,16}$/;
    const flag = regexpName.test(value);
    if (flag) {
      callback();
    } else {
      callback(
        new Error('限制16个字符，且不能输入空格和以下字符！@#￥%$^&*"、（）<>……'),
      );
    }
  };
  
  // 16英文名称校验
  export const validateNameEn16 = (rule, value, callback) => {
    const regexp = /^[^！@#￥%……&*（）<>"!@#$%^&*()、\s\u4e00-\u9fa5]{1,16}$/;
    const flag = regexp.test(value);
    if (flag) {
      callback();
    } else {
      callback(
        new Error(
          '限制16个字符，且不能输入中文、空格和以下字符！@#￥%$^&*"、（）<>……',
        ),
      );
    }
  };
  
  // 20中文名称校验
  export const validateName20 = (rule, value, callback) => {
    const regexpName = /^[^！@#￥%……&*（）<>" \s]{1,20}$/;
    const flag = regexpName.test(value);
    if (flag) {
      callback();
    } else {
      callback(new Error('1-20个字符，且不能输入以下字符 ！@#￥%……&*（）'));
    }
  };
  // 64位中文名称校验且可以输入空格
  export const validateName64 = (rule, value, callback) => {
    const regexpName = /^[^！@#￥%……&*（）<>"!@#$%^&*()、]{1,64}$/;
    const flag = regexpName.test(value);
    if (flag) {
      callback();
    } else {
      callback(
        new Error('限制64个字符，且不能输入以下字符！@#￥%$^&*"、（）<>……'),
      );
    }
  };
  // 最多可输入16个字符，仅支持中英文和数字
  export const name16 = (rule, value, callback) => {
    const regexp = /^[\u4e00-\u9fa5A-Za-z0-9]{1,16}$/;
    const flag = regexp.test(value);
    if (flag) {
      callback();
    } else {
      callback(new Error('最多可输入16个字符，仅支持中英文和数字'));
    }
  };
  
  // 1到16个英文字符且不包含空格
  export const en16 = (rule, value, callback) => {
    const regexp = /^[a-zA-Z]{1,16}$/;
    const flag = regexp.test(value);
    if (flag) {
      callback();
    } else {
      callback(new Error('请输入1到16个英文字符且不包含空格'));
    }
  };
  
  // IPV4
  export const validIpv4 = (rule, str, callback) => {
    const regex =
      /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    const flag = regex.test(str);
    if (flag) {
      callback();
    } else {
      callback(new Error('请输入正确的IPV4地址'));
    }
  };
  
  // 表别名中文名称
  export const validInput = (rule, str, callback) => {
    // 支持中文、英文、数字、-_*，最多32个字符
    const regex = /^[a-zA-Z0-9\u4e00-\u9fa5-_*\u3000]{1,32}$/;
    const flag = regex.test(str);
  
    if (flag) {
      callback();
    } else {
      callback(new Error('仅支持中英文、数字、-_*，且最多32个字符'));
    }
  };
  
  // 表别名英文名称
  export const validEnInput = (rule, str, callback) => {
    // 支持中文、英文、数字、-_*，最多32个字符
    const regex =
      /^(?=.{1,32}$)[^A-Z\\\/\*\?"<>\| ,#]+[^A-Z\\\/\*\?"<>\| ,#]*\*$/;
    const flag = regex.test(str);
  
    if (flag) {
      callback();
    } else {
      callback(
        new Error(
          '表别名以*号结尾，*号前不能包含大写英文字符，以及，/，*，?，"，<，>，|，(空格)，,，#等字符',
        ),
      );
    }
  };
  
  // url
  export const isUrl = (str) => {
    const reg =
      /^(?:http(?<prot>s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/;
    return reg.test(str);
  };
  